local yuechaox = fk.CreateSkill {
  name = "yuechaox",
  tags = { Skill.Wake },
}

Fk:loadTranslationTable {
  ["yuechaox"] = "月潮汐",
  [":yuechaox"] = "觉醒技，你的体力上限变化至小于等于0前，你防止之，然后获得场上其他角色所有的体力上限与手牌上限，且其他角色造成的伤害改为x。（x为你10％体力上限）",
}

yuechaox:addEffect(fk.BeforeMaxHpChanged, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(yuechaox.name) and player:usedSkillTimes(yuechaox.name, Player.HistoryGame) == 0
  end,
  can_wake = function(self, event, target, player, data)
    return player.maxHp + data.num <= 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data:preventMaxHpChange()
    -- 获取场上其他角色的体力上限与手牌上限
    local totalMaxHp = 0
    local totalMaxHandcard = 0
    for _, p in ipairs(room:getOtherPlayers(player)) do
      totalMaxHp = totalMaxHp + p.maxHp
      totalMaxHandcard = totalMaxHandcard + p:getMaxCards()
    end
    room:changeMaxHp(player, totalMaxHp)
    room:setPlayerMark(player, "extra_max_cards", totalMaxHandcard)
  end,
})

yuechaox:addEffect("maxcards", {
  correct_func = function(self, player)
    if player:hasSkill(yuechaox.name) then
      return player:getMark("extra_max_cards")
    end
  end,
})

-- 添加伤害修正效果
yuechaox:addEffect(fk.DetermineDamageCaused, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return  data.from and player:hasSkill(yuechaox.name) and data.from ~= player and player:usedSkillTimes(yuechaox.name, Player.HistoryGame) > 0
  end,
  on_use = function(self, event, target, player, data)
    data.damage = player.maxHp * 0.1
  end
})


return yuechaox
